﻿<p class="smallNav">专业量表管理 >> 量表编辑 >> 定义常模 >></p>


<br/>
<%= javascript_tag "window._token = '#{form_authenticity_token}'" if ActionController::Base.allow_forgery_protection %>
<%= javascript_include_tag "prototype", "effects"%>

<div>
  <div id="listDiv">
    <!--题目列表--->
    <%= render :partial => "norms", :object => @test %>

  </div>

  <!--a href="javascript:;" onclick="Element.show('form_div');" style="margin-left:400px">添加题目</a-->
  <!-- 添加表单-->
  <div id="form_div" style="margin-left:0px"><br/>
    
    <% remote_form_for :norm, @norm, :url => {:action => "create_norm"},
          :html => { :method => :post, :class => "edit_post", :id => "form0" } do |f| %>
      <input type="hidden" value="<%=@test.id%>" name="test_id" id="hid_test_id"/>

      <table>
        <tr>
          <% if @test.norm_info.consider_item %>
          <td>考察项目细分</td>
          <% end %>
          <% if @test.norm_info.consider_sex %>
          <td>性别因素</td>
          <% end %>
          <% if @test.norm_info.consider_age %>
          <td>年龄因素</td>
          <% end %>
       
          <td>样本均数</td>
          <td>样本标准差</td>
          <td width="">样本数</td>
          <td></td>
        </tr>
        <tr>
          <td>
            <% if @test.norm_info.consider_item == NORM_ITEM_TYPE_NUM %>
            <%= hidden_field_tag "norm[item_type]", NORM_ITEM_TYPE_NUM%>
            <%= NORM_ITEM_TYPE_NUM %>
            <% end %>
            <% if @test.norm_info.consider_item == NORM_ITEM_TYPE_PART %>
            <%= hidden_field_tag "norm[item_type]", NORM_ITEM_TYPE_NUM%>
            <%= NORM_ITEM_TYPE_PART %>:
            <%= select("norm", "item_id", Part.find_all_by_test_id(@test.id).collect {|p| [ p.name, p.id ] }) %>
            <% end %>
            <% if @test.norm_info.consider_item == NORM_ITEM_TYPE_DIMEN %>
            <%= hidden_field_tag "norm[item_type]", NORM_ITEM_TYPE_NUM%>
            <%= NORM_ITEM_TYPE_DIMEN %>:
            <%= select("norm", "item_id", Dimen.find_all_by_test_id(@test.id).collect {|p| [ p.name, p.id ] }) %>
            <% end %>
            
            <!--
            <%= select "norm", "item_type",  @item_types, {},
                   :onchange => remote_function(
                     :update => "sub_items",
                     :with => "'item_type=' + value + '&test_id=' + $('hid_test_id').value",
                     :url => {:controller => "surveys/prof_surveys", :action => "items_by_type"})
                   %>
            <span id="sub_items">
              
            </span>
            -->
          </td>
          <% if @test.norm_info.consider_sex %>
          <td>
            <%= select("norm", "sex", [[SEX_MALE, SEX_MALE], [SEX_FEMALE, SEX_FEMALE]] ) %>
          </td>
          <% end %>
          <% if @test.norm_info.consider_age %>
          <td>
            <%= age_select "norm", "age_start" %>
            到
            <%= age_select "norm", "age_end" %>
          </td>
          <% end  %>
          <td>
            <%= f.text_field "specimen_avg", :size => 6 %>
          </td>
          <td>
            <%= f.text_field "specimen_standard_deviation", :size => 6 %>
          </td>
          <td>
            <%= f.text_field "specimen_num", :size => 6 %>
          </td>
          <td>&nbsp;&nbsp;
            <input type="button" value="添加" onclick="saveQuestion($('form0'));"
                   class="cButton"/>&nbsp;&nbsp;
          </td>
        </tr>
      </table>
     
    <% end %>

    </form>
    <br/>

  </div>
  <!-- quesiton添加表单结束 -->

</div>

<div>
</div>

<input type="button" value="完成"  style="margin-left: 250px"
       onclick="window.location='/surveys/prof_surveys/edit/<%=@test.id%>'"
           
<script type="text/javascript">
//变量声明
var question_id = 0;
var choice_num = 2;

//给题目添加一个选项
function addChoice(parent, id) {
  parent.appendChild(createChoice(id, true));
}

//创建一个选项
function createChoice(id, isRemove) {
  var choiceDiv = document.createElement("div");
  var a = createA("javascript:;", "<font color=red>删除</font>")
  a.onclick = function(){ removeElement(choiceDiv) }

  choiceDiv.id = id;
  choiceDiv.appendChild(createLabel("选项"));
  choiceDiv.appendChild(createTextField("choice.content[]"));

  choiceDiv.appendChild(createLabel("&nbsp;&nbsp;"));

  choiceDiv.appendChild(createLabel("分值"));
  choiceDiv.appendChild(createTextField("choice.value[]"));

  if(isRemove){
    choiceDiv.appendChild(a);
  }

  choice_num++;
  return choiceDiv;
}

//删除自身
function removeElement(el){
  el.parentNode.removeChild(el);
}

//创建textfield
function createTextField(name) {
  var newInput = document.createElement("input");
  newInput.type = "text";
  newInput.name = name;
  return newInput;
}

//创建换行符
function br(){
  return document.createElement("br");
}

//创建文本
function createLabel(content){
  var label = document.createElement("span");
  label.innerHTML = content;
  return label;
}

//创建链接
function createA(href, content) {
  var a = document.createElement("a");
  a.href = href;
  a.innerHTML = content;
  return a;
}

//创建select
function createSelect(name){
  var select = document.createElement("select");
  select.name = name;
  select.appendChild(createOption("<%=TEST_TYPE_TREND%>", "<%=TEST_TYPE_TREND%>"));
  select.appendChild(createOption("<%=TEST_TYPE_JUMP%>", "<%=TEST_TYPE_JUMP%>"));
  select.appendChild(createOption("<%=TEST_TYPE_COUNT%>", "<%=TEST_TYPE_COUNT%>"));
}

//创建option
function createOption(value, content){
  var option = document.createElement("option");
  option.value = value;
  option.innerHTML = content;
  return option;
}

//创建按钮
function　createInput(value, type) {
  var input = document.createElement("input");
  input.value = value;
  input.type = type;
  return input;
}

//异步保存题目
function saveQuestion(form) {
    new Ajax.Updater(
      "listDiv",
      form.action,
      {
        //method: "post",
        asynchronous: true,
        evalScripts: true,
        parameters: Form.serialize(form) + '&authenticity_token=' + window._token
      }
    );
}

//删除所有子节点
function removeAllNodes(parentNode){
  while (parentNode.firstChild) {
    var oldNode = parentNode.removeChild(parentNode.firstChild);
    oldNode = null;
  }
}

window.onload = function() {
}
</script>
